package me.itsoo.artemis.framework.core.converter.number;

/**
 * IntegerTypeConvertor
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/18
 */
public class IntegerTypeConvertor implements NumberTypeConvertor {

    @Override
    public Object convertIfNecessary(Object value) {
        if (value == null) {
            return null;
        }

        if (value instanceof Integer) {
            return value;
        }

        if (value instanceof Number) {
            return ((Number) value).intValue();
        }

        if (value instanceof String) {
            try {
                return Integer.parseInt((String) value);
            } catch (Exception e) {
                return null;
            }
        }

        return null;
    }
}
